<?php

class CoffeeRecommend extends CActiveRecord
{
	/**
	 * The followings are the available columns in table '{{coffeerecommend}}':
	 * @var integer $id
	 * @var string $name
	 * @var string $ownerName
	 * @var string $street
	 * @var string $suburb
	 * @var string $city
	 * @var string $state
	 * @var string $postcode
	 * @var string $country
	 * @var string $website
	 * @var string $phone
	 * @var string $email
	 * @var string $baristaNames
	 * @var string $espressoMachine
	 * @var integer $beansForSale
	 * @var integer $internetAccess
	 * @var integer $roastingOnSite
	 * @var string $coffeeBrand
	 * @var string $comment
	 * @var integer $status
	 * @var integer $shopId
	 */
	
	const STATUS_PENDING='0';
	const STATUS_REJECTED='1';
	const STATUS_APPROVED='2';

	public static function status_options($status=null){
		$status_options= array(
		self::STATUS_PENDING=>'Pending',
		self::STATUS_REJECTED=>'Rejected',
		self::STATUS_APPROVED=>'Approved',
		);
		$status=strval($status);
		if($status!==null&&isset($status_options[$status])){
			return $status_options[$status];
		}
		return $status_options;
	}

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{coffeerecommend}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, comment, status, email', 'required'),
			array('beansForSale, internetAccess, roastingOnSite, wifi, goodForBusiness, status, shopId', 'numerical', 'integerOnly'=>true),
			array('name, ownerName, street, website, email', 'length', 'max'=>255),
			array('suburb, city, state, postcode, country, phone, baristaNames, espressoMachine, coffeeBrand', 'length', 'max'=>32),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, ownerName, street, suburb, city, state, postcode, country, website, phone, email, baristaNames, espressoMachine, beansForSale, internetAccess, roastingOnSite, wifi, goodForBusiness, coffeeBrand, comment, status, shopId', 'safe', 'on'=>'search'),
		
			array('comment','default','value'=>'','setOnEmpty'=>true,'on'=>'insert,update'),
			array('day1Start, day1End, day2Start, day2End, day3Start, day3End, day4Start, day4End, day5Start, day5End, day6Start, day6End, day7Start, day7End','default','value'=>'','setOnEmpty'=>true,'on'=>'insert,update'),
			
			);
		
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'shop' => array(self::BELONGS_TO, 'CoffeeShop', 'shopId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'name' => 'Cafe Name',
			'ownerName' => 'Owner Name',
			'street' => 'Street',
			'suburb' => 'Suburb',
			'state' => 'State',
			'city'=>'City',
			'postcode' => 'Postcode',
			'country' => 'Country',
			'website' => 'Website',
			'phone' => 'Phone',
			'email' => 'Email',
			'baristaNames' => 'Barista Names',
			'espressoMachine' => 'Espresso Machine',
			'beansForSale' => 'Beans For Sale',
			'internetAccess' => 'Internet Access',
			'roastingOnSite' => 'Roasting On Site',
			'wifi' => 'WiFi',
			'goodForBusiness' => 'Good for business meets',
			'coffeeBrand' => 'Coffee Brand',
			'comment' => 'Comment',
			'status' => 'Status',
			'shopId' => 'Shop',
		'day1Start' => 'Monday Open',
			'day1End' => 'Monday Close',
			'day2Start' => 'Tuesday Open',
			'day2End' => 'Tuesday Close',
			'day3Start' => 'Wednesday Open',
			'day3End' => 'Wednesday Close',
			'day4Start' => 'Thursday Open',
			'day4End' => 'Thursday Close',
			'day5Start' => 'Friday Open',
			'day5End' => 'Friday Close',
			'day6Start' => 'Saturday Open',
			'day6End' => 'Saturday Close',
			'day7Start' => 'Sunday Open',
			'day7End' => 'Sunday Close',
		
		
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		//$criteria->compare('ownerName',$this->ownerName,true);

		//$criteria->compare('street',$this->street,true);

		$criteria->compare('suburb',$this->suburb,true);

		//$criteria->compare('state',$this->state,true);

		//$criteria->compare('postcode',$this->postcode,true);

		//$criteria->compare('country',$this->country,true);

		//$criteria->compare('website',$this->website,true);

		//$criteria->compare('phone',$this->phone,true);

		//$criteria->compare('email',$this->email,true);

		//$criteria->compare('baristaNames',$this->baristaNames,true);

		//$criteria->compare('espressoMachine',$this->espressoMachine,true);

		//$criteria->compare('beansForSale',$this->beansForSale);

		//$criteria->compare('internetAccess',$this->internetAccess);

		//$criteria->compare('roastingOnSite',$this->roastingOnSite);

		//$criteria->compare('coffeeBrand',$this->coffeeBrand,true);

		//$criteria->compare('comment',$this->comment,true);

		$criteria->compare('status',$this->status);

		//$criteria->compare('shopId',$this->shopId);
		
		$criteria->order='id desc';

		return new CActiveDataProvider('CoffeeRecommend', array(
			'criteria'=>$criteria,
		));
	}
}